<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use backend\components\Helper;
use common\models\Category;
use yii\helpers\ArrayHelper;
use common\models\Weixin;
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 18-1-11
 * Time: 下午5:18
 */
?>
<style>
    .table-bordered {
        border: 0px;
    }
    .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
        border: 0px;
        border-top: 1px solid #ddd;
        border-bottom: 1px solid #ddd;
    }
</style>
<section id="all-result">
    <div class="container" id="show-head">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <h3 id="title">所有文章</h3>
            </div>
        </div>
    </div>

    <div class="col-md-10 col-md-offset-1" >
        <?php Pjax::begin(); ?>    <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'summary' => "",
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
                [
                    'attribute'=>'title',
                    'format'=>'raw',
                    'value'=> function($data){
                        $content = $data['title'];
                        $data->id;
                        //$a = Html::tag('span',Html::a(Helper::truncate_utf8_string($content,20),[''],['class'=>'','']),['class'=>'results-title']);
                        $a = '<span style="cursor: pointer;" class="results-title"><a data-id="'. $data->id .'">'.Helper::truncate_utf8_string($content,20).'</a></span>';
                        return $a;
                    },
                ],
                [
                    'attribute'=>'type',
                    'value'=> function($data){
                        $type  = Category::find()->all();
                        $ds = ArrayHelper::map($type,'id', 'name');
                        return $data['type'];
                    },
                ],
                'createat'
            ],
        ]); ?>
        <?php Pjax::end(); ?>
    </div>
</section>
<?= Html::jsFile('@web/assets/jquery/jquery-3.2.1.min.js')?>
<?php $weixin = Weixin::find()->one(); ?>
<script>

    //微信公众号弹出
    $(function(){
        $('#wx-public').popover({
            trigger : 'hover',//鼠标以上时触发弹出提示框
            html:true,//开启html 为true的话，data-content里就能放html代码了
            content:"<img id='wx-public-img' src='http://www.qiwangxiao.com/images/about/weixin.jpg'>",
            placement:'top'
        });

        // 扫码阅读弹层
        function wxModal(url,id){

            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    type:1,
                    title:'扫码阅读',
                    btn:'确定',
                    scrollbar: false,
                    offset: 'auto',
                    area: ['500px', '500px'],
                    content:'<img width="300" height="300" src='+url+'><p style="text-align: center">扫描图中二维码，获取验证码<br/>在下列输入框输入后阅读</p>' +
                    '<input type="text" style="width: 300px; height: 30px;font-size: 16px;" id="reg-ipt" placeholder="请输入验证码">'
                    +'<p id="err-tip"></p>',
                    yes:function(index){
                        var $reg = $('#reg-ipt').val();
                        var code = <?php echo $weixin->code ? $weixin->code : 0 ?>;
                        if($reg != code){
                            $('#reg-ipt').css('border','1px solid #f00');
                            $('#err-tip').text('验证码错误！').show();
                        }else{
                            $(location).prop('href', '/index.php?r=post/view&id='+id)
                            $('#reg-ipt').css('border','1px solid #ccc');
                            $('#err-tip').hide();
                        }
                    }
                });
            });

        }
        $('.results-title a').each(function(){
            $(this).click(function(){
                var reg_id =$(this).data("id");
                wxModal("./dingyuehao.jpg",reg_id)
            })
        });
    })
</script>